說明
在與綠界科技進行資料傳遞時,除了檢查碼[CheckMacValue]參數外,其餘所有參數皆需要加入檢查碼的檢核機制。
待加密的字串
MerchantID=2000933&MerchantTradeNo=A20130312153023&MerchantTradeDate=2013/03/12 15:30:23&LogisticsType=CVS&LogisticsSubType=FAMIC2C&GoodsAmount=1000&IsCollection=N&ServerReplyURL=https://www.ecpay.com.tw/ServerReplyURL&SenderName=寄件者姓名&ReceiverName=收件者姓名&ReceiverStoreID=001779
檢核碼計算順序
(1) 將傳遞參數依照第一個英文字母,由A到Z的順序來排序(遇到第一個英名字母相同時,以第二個英名字母來比較,以此類推),並且以&方式將所有參數串連。
GoodsAmount=1000&IsCollection=N&LogisticsSubType=FAMIC2C&LogisticsType=CVS&MerchantID=2000933&MerchantTradeDate=2013/03/12 15:30:23&MerchantTradeNo=A20130312153023&ReceiverName=收件者姓名&ReceiverStoreID=001779&SenderName=寄件者姓名&ServerReplyURL=https://www.ecpay.com.tw/ServerReplyURL
(2) 參數最前面加上HashKey、最後面加上HashIV
HashKey=XBERn1YOvpM9nfZc&GoodsAmount=1000&IsCollection=N&LogisticsSubType=FAMIC2C&LogisticsType=CVS&MerchantID=2000933&MerchantTradeDate=2013/03/12 15:30:23&MerchantTradeNo=A20130312153023&ReceiverName=收件者姓名&ReceiverStoreID=001779&SenderName=寄件者姓名&ServerReplyURL=https://www.ecpay.com.tw/ServerReplyURL&HashIV=h1ONHk4P4yqbl5LK
(3) 將整串字串進行URL encode
HashKey%3dXBERn1YOvpM9nfZc%26GoodsAmount%3d1000%26IsCollection%3dN%26LogisticsSubType%3dFAMIC2C%26LogisticsType%3dCVS%26MerchantID%3d2000933%26MerchantTradeDate%3d2013%2f03%2f12+15%3a30%3a23%26MerchantTradeNo%3dA20130312153023%26ReceiverName%3d%e6%94%b6%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26ReceiverStoreID%3d001779%26SenderName%3d%e5%af%84%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26ServerReplyURL%3dhttps%3a%2f%2fwww.ecpay.com.tw%2fServerReplyURL%26HashIV%3dh1ONHk4P4yqbl5LK
若使用PHP進行URL encode
HashKey%3dXBERn1YOvpM9nfZc%26GoodsAmount%3d1000%26IsCollection%3dN%26LogisticsSubType%3dFAMIC2C%26LogisticsType%3dCVS%26MerchantID%3d2000933%26MerchantTradeDate%3d2013%2f03%2f12%2015%3a30%3a23%26MerchantTradeNo%3dA20130312153023%26ReceiverName%3d%e6%94%b6%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26ReceiverStoreID%3d001779%26SenderName%3d%e5%af%84%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26ServerReplyURL%3dhttps%3a%2f%2fwww.ecpay.com.tw%2fServerReplyURL%26HashIV%3dh1ONHk4P4yqbl5LK
(4) 轉為小寫
hashkey%3dxbern1yovpm9nfzc%26goodsamount%3d1000%26iscollection%3dn%26logisticssubtype%3dfamic2c%26logisticstype%3dcvs%26merchantid%3d2000933%26merchanttradedate%3d2013%2f03%2f12+15%3a30%3a23%26merchanttradeno%3da20130312153023%26receivername%3d%e6%94%b6%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26receiverstoreid%3d001779%26sendername%3d%e5%af%84%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26serverreplyurl%3dhttps%3a%2f%2fwww.ecpay.com.tw%2fserverreplyurl%26hashiv%3dh1onhk4p4yqbl5lk
若使用PHP進行URL encode
hashkey%3dxbern1yovpm9nfzc%26goodsamount%3d1000%26iscollection%3dn%26logisticssubtype%3dfamic2c%26logisticstype%3dcvs%26merchantid%3d2000933%26merchanttradedate%3d2013%2f03%2f12%2015%3a30%3a23%26merchanttradeno%3da20130312153023%26receivername%3d%e6%94%b6%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26receiverstoreid%3d001779%26sendername%3d%e5%af%84%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26serverreplyurl%3dhttps%3a%2f%2fwww.ecpay.com.tw%2fserverreplyurl%26hashiv%3dh1onhk4p4yqbl5lk
(5) 依urlencode轉換表更換字元 (若使用PHP進行URL encode時使用)
hashkey%3dxbern1yovpm9nfzc%26goodsamount%3d1000%26iscollection%3dn%26logisticssubtype%3dfamic2c%26logisticstype%3dcvs%26merchantid%3d2000933%26merchanttradedate%3d2013%2f03%2f12+15%3a30%3a23%26merchanttradeno%3da20130312153023%26receivername%3d%e6%94%b6%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26receiverstoreid%3d001779%26sendername%3d%e5%af%84%e4%bb%b6%e8%80%85%e5%a7%93%e5%90%8d%26serverreplyurl%3dhttps%3a%2f%2fwww.ecpay.com.tw%2fserverreplyurl%26hashiv%3dh1onhk4p4yqbl5lk
(6) 以MD5加密方式來產生雜凑值
MD5:692fd6e2cdb539ccdb7206c76dc239ad
(7) 再轉大寫產生CheckMacValue
MD5:692FD6E2CDB539CCDB7206C76DC239AD
注意事項:
- 請特店接收到綠界傳送的資訊時,必須檢查檢查碼[CheckMacValue]是否正確,如未判斷特店可能產生損失。
- 請確認您的語言的 UrlEncode function 轉換後的結果符合附錄URLENCODE轉換表中的「.NET編碼(ecpay)」欄位值,若有不符合的字元,請用字元替換功能處理,以免無法符合檢查規則。
例如:PHP urlencode function會將 ! 字元編碼成 %21,不符合「.NET編碼(ecpay)」,所以在 PHP urlencode後需用 str_replace function 將%21轉回 ! 字元。以下僅以 PHP轉換範例說明:
$sMacValue = str_replace(‘%2d’, ‘-‘, $sMacValue);
$sMacValue = str_replace(‘%5f’, ‘_’, $sMacValue);
$sMacValue = str_replace(‘%2e’, ‘.’, $sMacValue);
$sMacValue = str_replace(‘%21’, ‘!’, $sMacValue);
$sMacValue = str_replace(‘%2a’, ‘*’, $sMacValue);
$sMacValue = str_replace(‘%28’, ‘(‘, $sMacValue);
$sMacValue = str_replace(‘%29’, ‘)’, $sMacValue);
其它程式語言的轉換功能,請閱該程式語言的編碼轉換規則改寫。